package com.company;

import java.util.Scanner;

import static com.company.NGuessNumber.generateAnswer;
import static com.company.NGuessNumber.getPlayerInput;

public class Main {


    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        NGuessNumber nGuessNumber = new NGuessNumber();
        //定义变量 可更改
        String input;
        do {
            // 生成答案 并存到test数组中
            int[] test = generateAnswer();
            while (true) {
                //设置变量a 存入compareGuessAnswer方法返回的a的数量
                int a = nGuessNumber.compareGuessAnswer(test, getPlayerInput());
                if (a == 4) {
                    System.out.println("你猜对了！你好棒！");
                    break;
                } else {
                    // %d 替换符
                    System.out.printf("%dA%dB \n", a, (4 - a));
                }
            }
            System.out.println("继续游戏请输入y,输入n则退出游戏");
            while (true) {
                //判断用户输入
                input = scanner.next();
                if ("y".equals(input) || "n".equals(input)) {
                    break;
                } else {
                    System.out.println("输入有误");
                }
            }
        } while ("y".equals(input));
    }


}

